#include "Store.hh"
#include <iostream>

Store::Store() {
    itemsForSale.push_back(new Item("Health Potion", "Restores 20 HP", 10, 20, 0, 0,0));
    itemsForSale.push_back(new Item("Mana Potion", "Restores 15 Mana", 15, 0, 0, 0,15));
    itemsForSale.push_back(new Item("Sword", "Increases Attack by 5", 50, 0, 5, 0,0));
    itemsForSale.push_back(new Item("Great Mana Potion", "Restores 100 Mana", 100, 0, 0, 0,100));
    itemsForSale.push_back(new Item("The best Sword in your village", "Increases Attack by 1", 10, 0, 1, 0,0));
    itemsForSale.push_back(new Item("Great Health Potion", "Restores 40 HP", 15, 40, 0, 0,0));
    itemsForSale.push_back(new Item("Golden Sword", "Increases Attack by 10", 100, 0, 10, 0,0));
    itemsForSale.push_back(new Item("Golden armor","Increase Defense 10", 100, 0, 0, 10 ,0));
}


Store::~Store() {
    for (Item* item : itemsForSale) {
        delete item;
    }
}

void Store::displayItems() const {
    std::cout << "Store Items:\n";
    for (size_t i = 0; i < itemsForSale.size(); ++i) {
        std::cout << i + 1 << ". " << itemsForSale[i]->getName() << " (" << itemsForSale[i]->getDescription() << ") - $" << itemsForSale[i]->getValue() << "\n";
    }
}

bool Store::buyItem(Character& player, int index) {
    if (index >= 0 && index < itemsForSale.size()) {
        Item* item = itemsForSale[index];
        if (player.getMoney() >= item->getValue()) {
            player.setMoney(player.getMoney() - item->getValue());
            player.addToInventory(item);
            
            return true;
        } else {
            std::cout << "Not enough money to buy " << item->getName() << ".\n";
        }
    } else {
        std::cout << "Invalid item selection.\n";
    }
    return false;
}

std::vector<Item*>& Store::getItemsForSale() {
    return itemsForSale;
}